package com.example.demospringmybatisplus.service;

import com.example.demospringmybatisplus.entity.User;
import com.example.demospringmybatisplus.entity.Users;
import com.example.demospringmybatisplus.mapper.UsersMapper;
import com.example.demospringmybatisplus.utils.SetUtils;

import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

/**
 * 批量处理数据
 *
 * @author huahua
 * @DATE 2025/4/25
 **/
public class BatchDataService {
    @Resource
    private UsersMapper usersMapper;

    public List<Users> findUsersById(Set<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }
        List<Users> userList = new ArrayList<>();
        SetUtils.processInBatch(ids, 1000, batch -> userList.addAll(usersMapper.selectBatchIds(batch)));

        return userList;
    }
}
